<html>
<head><title>数据类型自动转换</title></head>
<body>
	<h3>数据类型自动转换</h3>
	<hr>
	<script>
		//直接拿来判断
		document.write("转换为逻辑型数据:<br><br>");

		var a=NaN, b=null, c=undefined, d=0, e="";
		var f=5, g="this";
		//分别使用变量作为判断条件,各变量自动转化为Boolean值
		if(a) {
			document.write("NaN -->true<br>");
		} else {
			document.write("NaN -->false<br>");
		}
		if(b) {
			document.write("a-->true<br>");
		} else {
			document.write("null -->false<br>");
		}
		if(c) {
			document.write("a-->true<br>");
		} else {
			document.write("undefinde -->false<br>");
		}
		if(d) {
			document.write("a-->true<br>");
		} else {
			document.write("0 -->false<br>");
		}
		if(e) {
			document.write("a-->true<br>");
		} else {
			document.write("空字符串 -->false<br>");
		}
		if(f) {
			document.write("数字5 -->true<br>");
		} else {
			document.write("a-->false<br>");
		}
		if(g) {
			document.write("非空字符串 -->true<br>");
		} else {
			document.write("g-->false<br>");
		}
		//通过加减1数字,来转化为数值型
		document.write("<hr>转换为数值型数据:<br>");
		var a=true, b=false, c=undefined, d=null, e="5";
		
		document.write("<br>a = " + a + " ; 转换后为: " + (a+1-1));
		document.write("<br>b = " + b + " ; 转换后为: " + (b+1-1));
		document.write("<br>c = " + c + " ; 转换后为: " + (c+1-1));
		document.write("<br>d = " + d + " ; 转换后为: " + (d+1-1));
		document.write("<br>e = " + e + " ; 转换后为: " + (-(-e)));
		//通过加空字符串,来转化成字符串型
		document.write("<br><hr>转换为字符串类型:<br>");
		var a=true, b=false, c=undefined, d=null, e=NaN, f=0, g=6;
		document.write("<br>a = " + a + " ; 转换后为: " + ("" + a));
		document.write("<br>b = " + b + " ; 转换后为: " + ("" + b));
		document.write("<br>c = " + c + " ; 转换后为: " + ("" + c));
		document.write("<br>d = " + d + " ; 转换后为: " + ("" + d));
		document.write("<br>e = " + e + " ; 转换后为: " + ("" + e));
		document.write("<br>e = " + e + " ; 转换后为: " + ("" + f));
		document.write("<br>e = " + e + " ; 转换后为: " + ("" + g));
		document.write
	</script>
</body>
</html>